package com.xieyunjie.config;

import com.xieyunjie.domain.User;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration  //相当于创建一个spring的xml文件
public class JavaConfigA {

    @Bean("user1")  //相关于xml里面<bean id="user" name="user" class="com.xieyunjie.domain.User"  >
//    @Primary
    public User getUser1() {
        return new User(1, "小明", "武汉");
    }

    @Bean("user2")  //相关于xml里面<bean id="user" name="user" class="com.xieyunjie.domain.User"  >
    public User getUser2() {
        return new User(2, "小张", "武汉");
    }

    @Bean("user3")
    public User getUser2(@Qualifier("user2") User user) {
        user.setName("小红");
        return user;
    }

}
